package com.sskj.finance.presenter;

import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.finance.bean.HomeLendBlend;
import com.sskj.finance.bean.HomeLendLendCoinListBean;
import com.sskj.finance.http.HttpConfig;
import com.sskj.finance.ui.activity.IWantFinanceActivity;
import com.sskj.lib.http.JsonCallBack;

import java.util.List;


public class IWantFinanceActivityPresenter extends BasePresenter<IWantFinanceActivity> {
    /**
     * 理财币种列表
     *
     * @return
     */
    public void homeLendLendCoinList() {
        httpService.homeLendLendCoinList().execute(new JsonCallBack<HttpData<List<HomeLendLendCoinListBean>>>() {
            @Override
            public void onSuccess(Response<HttpData<List<HomeLendLendCoinListBean>>> response) {
                HttpData<List<HomeLendLendCoinListBean>> httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {
                    mView.updateUI(httpData.getData());
                }
            }
        });
    }

    /**
     * 理财挂单
     *
     * @param code    理财币种标识，如：BTC、ETH
     * @param num     理财数量
     * @param rate    利率
     * @param days    周期(天)
     * @param is_auto 1自动放贷 0手动
     * @param tpwd    资金密码
     * @return
     */
    public void homeLendLendAdd(String code, String num, String rate, String days, String is_auto, String tpwd) {
        httpService.homeLendLendAdd(code, num, rate, days, is_auto, tpwd).execute(new JsonCallBack<HttpData>(this) {
            @Override
            public void onSuccess(Response<HttpData> response) {
                HttpData httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {

                    mView.addSuccess();
                }
            }
        });
    }


    /**
     * 理财统计
     *
     * @param code 理财币种标识，如：BTC、ETH
     * @return
     */
    public void homeLendBlend(String code) {
        httpService.homeLendBlend(code).execute(new JsonCallBack<HttpData<HomeLendBlend>>() {
            @Override
            public void onSuccess(Response<HttpData<HomeLendBlend>> response) {
                HttpData<HomeLendBlend> httpData = response.body();
                if (httpData.getStatus() == HttpConfig.OK) {

                    mView.updateHead(httpData.getData());
                }
            }
        });
    }
}
